package com.econorma.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.econorma.Application;
import com.econorma.export.ExportToJson;
import com.econorma.importa.ImportFromJson;

public class MainWindow extends JFrame implements ActionListener {

	private final Application app;
	
	public MainWindow(Application app){
		this.app=app;
		init();
	}
	
	public void init(){
		
		
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setLayout(new FlowLayout());
		
		JButton ib = new JButton("Import");
		JButton eb = new JButton("Export");
		
		
		add(ib);
		add(eb);
		
		ib.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {

				ImportFromJson im = new ImportFromJson(app.getDao());
				im.importa();
				
				JOptionPane.showMessageDialog(null, "Import eseguito con successo" ,"Info", JOptionPane.INFORMATION_MESSAGE);
				
				
			}
		});
		
		eb.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {

				ExportToJson ex = new ExportToJson(app.getDao());
				ex.export();
				
				JOptionPane.showMessageDialog(null, "Export eseguito con successo" ,"Info", JOptionPane.INFORMATION_MESSAGE);
			}
		});
		
		
		
		setPreferredSize(new Dimension(400, 400));
		
		pack();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
	 
		
	}
	
	
	 
}
